import java.util.concurrent.atomic.AtomicInteger;
class Conter{
    public int add(int n){
        synchronized (Conter.class){
            n = n+1;
        }
        return n;
    }
}
public class Main {
    private static int count = 0;
    public static void main(String[] args) throws InterruptedException {

        Conter conter = new Conter();
        Thread t = new Thread(()->{
            for(int i = 0; i<10000; i++){
                synchronized (conter){  // 使用其他类来创建锁，并使用该类中的方法
                    count = conter.add(count);
                }
            }
        });
        t.start();
        t.join();

        System.out.println(count);
    }
}
